<template>
  <div class="mod-config">
    <el-form inline v-show="searchShow" :model="dataForm" @keyup.enter.native="searchChange()">
      <el-form-item label="代码" prop="code">
        <el-input v-model="dataForm.code" placeholder="代码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="searchChange">查询</el-button>
        <el-button type="default" icon="el-icon-delete" @click="searchReset">清空</el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-col :span="24">
        <el-button v-if="permissions.eims_salerefunddetail_add" icon="el-icon-plus" type="primary"  @click="addOrUpdateHandle()">新增</el-button>
        <el-button icon="el-icon-search" circle @click="handleSearchShow" style="float:right;"></el-button>
        <el-button icon="el-icon-refresh" circle @click="refreshChange" style="float:right;"></el-button>
      </el-col>
    </el-row>
    <div class="avue-crud">
      <el-table :data="dataList" border v-loading="dataListLoading">
        <el-table-column prop="id" label="主键id"></el-table-column>
        <el-table-column prop="billId" label="单号"></el-table-column>
        <el-table-column prop="saleId" label="销售单id"></el-table-column>
        <el-table-column prop="inStockId" label="入库仓库id"></el-table-column>
        <el-table-column prop="outStockId" label="出库仓库id"></el-table-column>
        <el-table-column prop="outStockTime" label="出库时间"></el-table-column>
        <el-table-column prop="goodsId" label="商品id"></el-table-column>
        <el-table-column prop="goodsCode" label="商品代码"></el-table-column>
        <el-table-column prop="goodsDisplayName" label="商品展示名称"></el-table-column>
        <el-table-column prop="supplyId" label="商品供应商id"></el-table-column>
        <el-table-column prop="ctgId" label="商品类别id"></el-table-column>
        <el-table-column prop="ctgSaleId" label="销售时具体商品类别id"></el-table-column>
        <el-table-column prop="goodsDescription" label="商品描述"></el-table-column>
        <el-table-column prop="goodsQuantity" label="商品数量"></el-table-column>
        <el-table-column prop="goodsCustomizeType" label="商品是否订做类型(1-是,0否)"></el-table-column>
        <el-table-column prop="noStockFlag" label="无库存标识(1-是,0-否)"></el-table-column>
        <el-table-column prop="selfFlag" label="商品是否为顾客自身物品(1-是,0-否)"></el-table-column>
        <el-table-column prop="giftFlag" label="商品是否为赠品(1-是,-0-否)"></el-table-column>
        <el-table-column prop="refundFlag" label="是否退款(1-是,0-否,2-退部分)"></el-table-column>
        <el-table-column prop="refundNumber" label="退货数量"></el-table-column>
        <el-table-column prop="refundAfterNumber" label="部分退货后剩余数量"></el-table-column>
        <el-table-column prop="refundAfterMoney" label="部分退货后剩余销售金额"></el-table-column>
        <el-table-column prop="refundAfterIntegral" label="部分退货后剩余销售积分"></el-table-column>
        <el-table-column prop="batch" label="批次"></el-table-column>
        <el-table-column prop="invalidTime" label="失效日期"></el-table-column>
        <el-table-column prop="productionDate" label="生产日期"></el-table-column>
        <el-table-column prop="registerNum" label="注册证号"></el-table-column>
        <el-table-column prop="price"label="单价金额(销售时单价)"></el-table-column>
        <el-table-column prop="originPrice" label="商品原价金额"></el-table-column>
        <el-table-column prop="originalPrice" label="原价总金额"></el-table-column>
        <el-table-column prop="discountPrice" label="折扣金额"></el-table-column>
        <el-table-column prop="removePrice" label="抹零金额"></el-table-column>
        <el-table-column prop="deductionPrice" label="积分和储值卡抵扣金额"></el-table-column>
        <el-table-column prop="deductionFinalPrice" label="抵扣完金额"></el-table-column>
        <el-table-column prop="receivablePrice" label="应收金额"></el-table-column>
        <el-table-column prop="oldIntegral" label="原来积分"></el-table-column>
        <el-table-column prop="integral" label="商品所得积分"></el-table-column>
        <el-table-column prop="discountType" label="折扣类型(1-员工打折权限,2-打折卡打折)"></el-table-column>
        <el-table-column prop="discountUserId" label="折扣人员id"></el-table-column>
        <el-table-column prop="discountRate" label="折扣率"></el-table-column>
        <el-table-column prop="outStorageFlag" label="出库标识(1-是,0否)"></el-table-column>
        <el-table-column prop="inStorageFlag" label="入库标识(1-是,0否)"></el-table-column>
        <el-table-column prop="glassFlag" label="镜片类型(L-左镜片,R-右镜片,F-镜架)"></el-table-column>
        <el-table-column prop="memo" label="备注"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button v-if="permissions.eims_salerefunddetail_edit" type="text" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
            <el-button v-if="permissions.eims_salerefunddetail_del" type="text" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="avue-crud__pagination">
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        background
        layout="total, sizes, prev, pager, next">
      </el-pagination>
    </div>
    <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
  </div>
</template>

<script>
  import {fetchEimsSaleRefundDetailList, delEimsSaleRefundDetailObj} from '@/api/eims/salerefunddetail'
  import TableForm from './eimssalerefunddetail-form'
  import {mapGetters} from 'vuex'
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        searchShow:true,
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        addOrUpdateVisible: false
      }
    },
    components: {
      TableForm
    },
    created () {
      this.getDataList()
    },
    computed: {
      ...mapGetters(['permissions'])
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        fetchEimsSaleRefundDetailList(Object.assign({
          current: this.pageIndex,
          size: this.pageSize
        })).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data.records
            this.totalPage = response.data.data.total
          }else{
            this.$message.error(response.data.msg)
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        this.$confirm('是否确认删除ID为' + id, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
          return delEimsSaleRefundDetailObj(id)
        }).then(response => {
          if(response.data.code == '0'){
            this.$message.success('删除成功')
            this.getDataList()
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      searchChange() {
        this.pageIndex=1;
        this.getDataList()
      },
      // 搜索清空
      searchReset () {
        this.$refs.searchForm.resetFields();
        this.getDataList(this.page)
      },
      handleSearchShow () {
        this.searchShow = !this.searchShow;
      },
      // 刷新回调
      refreshChange() {
        this.getDataList(this.page)
      }
    }
  }
</script>
